<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class AmalDonatur extends CorePerson {

    private $mDonatur; //ID Donatur

    public function __construct($pDonaturId = null) {
        if ($pDonaturId)
            $this->mDonatur= $pDonaturId;
    }

    public function GenerateDonaturId($pKodifikasiDonatur="0103", $pIdLength=11){
        $mQuery = new DBQueryParse();
        $tSQL = 'SELECT MAX(id_donatur) as max_id FROM sra_person WHERE id_donatur LIKE "'.$pKodifikasiDonatur.'%" ';
        $tRes = $mQuery->Execute($tSQL); //echo $tSQL.'<br>';
        if ($tRes->Count() == 1) {
            $tRes->MoveFirst();
            $tResult= $tRes->max_id;
        }
        
        if(is_null($tResult)) {
            $tResult='';
            $i=1;
            while($i<($pIdLength-strlen($pKodifikasiDonatur)) ){
                $tResult.= "0";
                $i++;
            }
            $tResult= $pKodifikasiDonatur.$tResult;
            $tResult.= "1";
        }
        else
            $tResult++;
        
        return $tResult;
    }
    
    //////////
    // L I S T 
    //////////
    public function GenerateListDonatur() {
        $mData = new DBQueryParse();
        $mData->SetTableName("view_sra_person");
        $mData->SetTableOrder("nama_lengkap");

        $mData->CreateField();
        $mData->SetFieldDB('id_donatur');
        $mData->SetFieldHeader('id donatur');
        
        $mData->CreateField();
        $mData->SetFieldDB('id_person');
        $mData->SetFieldHeader('id person');

        $mData->CreateField();
        $mData->SetFieldDB('nama_lengkap');
        $mData->SetFieldHeader('nama lengkap');

        $mData->CreateField();
        $mData->SetFieldDB('publikasi');
        $mData->SetFieldHeader('publikasi');

        $mData->CreateField();
        $mData->SetFieldDB('email');
        $mData->SetFieldHeader('email');

        $mData->CreateField();
        $mData->SetFieldDB('goldarah');
        $mData->SetFieldHeader('darah');

        $mData->CreateField();
        $mData->SetFieldDB('kota_lahir');
        $mData->SetFieldHeader('tempat lahir');

        $mData->CreateField();
        $mData->SetFieldDB('kota_lahir');
        $mData->SetFieldHeader('Tempat Lahir');

        $mData->CreateField();
        $mData->SetFieldDB('tanggal_lahir');
        $mData->SetFieldHeader('Tanggal Lahir');

        $mData->CreateField();
        $mData->SetFieldDB('pendidikan');
        $mData->SetFieldHeader('pendidikan');

        $mData->CreateField();
        $mData->SetFieldDB('kategori');
        $mData->SetFieldHeader('kategori');

        $mData->CreateField();
        $mData->SetFieldDB('kategori_ket');
        $mData->SetFieldHeader('kategori ket');

        $mData->CreateField();
        $mData->SetFieldDB('pekerjaan');
        $mData->SetFieldHeader('pekerjaan');

        $mData->CreateField();
        $mData->SetFieldDB('pekerjaan_ket');
        $mData->SetFieldHeader('pekerjaan ket');

        $mData->CreateField();
        $mData->SetFieldDB('media');
        $mData->SetFieldHeader('media');

        $mData->CreateField();
        $mData->SetFieldDB('media_ket');
        $mData->SetFieldHeader('media ket');

        $mData->CreateField();
        $mData->SetFieldDB('catatan');
        $mData->SetFieldHeader('catatan');

        return $mData;
    }

    
    //////////
    // M U T U A T O R
    //////////
    public function SetPersonId($pPersonId) {
        $this->mPersonId = $pPersonId;
        $this->GetDetailByPersonId();
    }

    public function GetDonaturIdByPersonId($pPersonId) {
        $mQuery = new DBQueryParse();
        $tSQL = "SELECT id_donatur FROM sra_person WHERE person_id = \"" . $pPersonId . "\" ";
        $tRes = $mQuery->Execute($tSQL);
        
        if ($tRes->Count() == 1) {
            $tRes->MoveFirst();
            $tDonaturId = $tRes->id_donatur;
        }
        return $tDonaturId;
    }
    
    public function GetPersonIdByDonaturId($pPersonId) {
        $mQuery = new DBQueryParse();
        $tSQL = "SELECT person_id FROM sra_person WHERE id_donatur = \"" . $pPersonId . "\" ";
        $tRes = $mQuery->Execute($tSQL);
        
        if ($tRes->Count() == 1) {
            $tRes->MoveFirst();
            $tPersonId = $tRes->person_id;
        }
        return $tPersonId;
    }

}

?>
